home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer (Italian) 30 / PC Gamer IT CD 30 1-2.iso / MOTS / GAMEDATA / RESOURCE / JKMRES.GOO / cog_force_chainlight.cog < prev    next >
Text File  |  1998-02-25  |  9KB  |  333 lines

  1. # Jedi Knight Cog Script
  2. #
  3. # FORCE_CLIGHTNING.COG
  4. #
  5. # FORCEPOWER Script - Force Chain Lightning
  6. #  Bin 39
  7. #
  8. # [YB]
  9. #
  10. # (C) 1997 LucasArts Entertainment Co. All Rights Reserved
  11.  
  12.  
  13. symbols
  14.  
  15. template    powerup                          local
  16.  
  17. int         player                           local
  18. int         victim                           local
  19. int         potential                        local
  20.  
  21. int         lightning_current                local
  22. int         lightning_from                   local
  23. int         lightning_to                     local
  24. int         count                            local
  25.  
  26. flex        cost=100.0                       local
  27. flex        targetcost=5                     local
  28. flex        targetcount=0                    local
  29. int         rank                             local
  30. flex        mana                             local
  31. flex        dot                              local
  32. flex        maxDot                           local
  33. flex        dist                             local
  34. flex        minDist                          local
  35.  
  36. int         type                             local
  37. int         retval=0                         local
  38. int         dummy=0                          local
  39.  
  40. template    lightning=+force_clightn         local
  41. sound       fireSound=ForceLightnin01.wav    local
  42.  
  43. vector      pos                              local
  44. vector      dir                              local
  45. int         sec                              local
  46.  
  47. int         inbubble=0                       local
  48.  
  49. message     startup
  50. message     activated
  51. message     deactivated
  52. message     pulse
  53. message     timer
  54. message     newplayer
  55. message     killed
  56. message     deselected
  57. message     selected
  58. message     enterbubble
  59. message     exitbubble
  60.  
  61. end
  62.  
  63. # ========================================================================================
  64.  
  65. code
  66.  
  67. startup:
  68.    player = GetLocalPlayerThing();
  69.    inbubble = 0;
  70.  
  71.    Return;
  72.  
  73. # ........................................................................................
  74.  
  75. activated:
  76.    if(inbubble) Return;
  77.  
  78.    // Cannot use power if blinded
  79.    if(GetActorFlags(player) & 0x800) Return;
  80.  
  81.    if(IsInvActivated(player, 39)) Return;
  82.  
  83.    mana = GetInv(player, 14);
  84.    rank = GetInv(player, 39);
  85.  
  86.    if(mana >= cost || GetInv(player, 14) >= GetInv(player, 69))
  87.    {
  88.       victim = -1;
  89.       SetInvActivated(player, 39, 1);
  90.       SetPulse(0.33);
  91.    }
  92.    Return;
  93.  
  94. # ........................................................................................
  95.  
  96. pulse:
  97.    targetCount = targetCount + 1;
  98.    if(targetCount == 3)
  99.    {
  100.       if(GetInv(player, 64) != 1) ChangeInv(player, 14, -targetCost);
  101.       targetCount = 0;
  102.    }
  103.  
  104.    victim = -1;
  105.    maxDot = 0;
  106.  
  107.    // Search for all players and actors.
  108.    potential = FirstThingInView(player, 20 + 10 * rank, 5.0, 0x404);
  109.    while(potential != -1)
  110.    {
  111.       if(
  112.          HasLOS(player, potential) &&
  113.          (potential != player) &&
  114.          (VectorDist(GetThingPos(player), GetThingPos(potential)) <= 1.25) &&
  115.          !(GetThingFlags(potential) & 0x200) &&
  116.          !(GetActorFlags(potential) & 0x100) &&
  117.          !((jkGetFlags(potential) & 0x20) && !IsInvActivated(player, 23)) &&
  118.          (jkGetBubbleDistance(potential) > 1.0)
  119.         )
  120.       {
  121.          dot = ThingViewDot(player, potential);
  122.          if(dot > maxDot)
  123.          {
  124.             victim = potential;
  125.             maxDot = dot;
  126.          }
  127.       }
  128.       potential = NextThingInView();
  129.    }
  130.  
  131.    // If we have a victim...
  132.    if(victim != -1)
  133.    {
  134.       jkSetTargetColors(18, 19, 20);
  135.       jkSetTarget(victim);
  136.    }
  137.    else
  138.    {
  139.       jkEndTarget();
  140.    }
  141.  
  142.    Return;
  143.  
  144. # ........................................................................................
  145.  
  146. deactivated:
  147.  
  148.    if((victim == -1) || (GetThingHealth(player) <= 0) || inbubble)
  149.    {
  150.       call stop_power;
  151.       Return;
  152.    }
  153.  
  154.    SetPulse(0);
  155.    jkEndTarget();
  156.  
  157.    mana = GetInv(player, 14);
  158.  
  159.    if(mana >= cost || GetInv(player, 14) >= GetInv(player, 69))
  160.    {
  161.       if(HasLOS(player, victim))             // check that we still have a LOS on it...
  162.       {
  163.          if(GetInv(player, 64) != 1) ChangeInv(player, 14, -cost);
  164.  
  165.          PlayMode(player, 24);
  166.  
  167.          PlaySoundThing(fireSound, player, 1.0, -1, -1, 0x80);
  168.  
  169.          // Send a "force disturbance"...
  170.          if(!IsMulti())
  171.             SendMessageExRadius(GetThingPos(player), cost, 0x4, splash, 39, 0, 0, 0);
  172.  
  173.          SetBinWait(player, 39, 1.0);
  174.  
  175.          lightning_from = player;
  176.          lightning_to = victim;
  177.          call throw_lightning;
  178.          lightning_current = victim;
  179.  
  180.          for(count = 2; count <= rank; count = count + 1)
  181.          {
  182.             call get_next_target;
  183.             if(victim != -1)
  184.             {
  185.                lightning_from = lightning_current;
  186.                lightning_to = victim;
  187.                call throw_lightning;
  188.                lightning_current = victim;
  189.             }
  190.             else
  191.             {
  192.                // no one is in range, apply damage to the current victim
  193.                if(!IsMulti())
  194.                {
  195.                   if((GetThingHealth(lightning_current) > 0) && (lightning_current != GetLocalPLayerThing()))
  196.                      DamageThing(lightning_current, (rank - count + 1) * 10, 0x08, player);
  197.                }
  198.                else
  199.                {
  200.                   if(!(GetThingFlags(lightning_current) & 0x200))
  201.                      retval = SkillTarget(lightning_current, player, 39, (rank - count + 1) * 10);
  202.                }
  203.  
  204.                SetInvActivated(player, 39, 0);
  205.                Return;
  206.             }
  207.          }
  208.  
  209.          SetInvActivated(player, 39, 0);
  210.          Return;
  211.       }
  212.    }
  213.  
  214.    SetInvActivated(player, 39, 0);
  215.  
  216.    Return;
  217.  
  218. # ........................................................................................
  219.  
  220. timer:
  221.    Return;
  222.  
  223. # ........................................................................................
  224.  
  225. selected:
  226.    jkPrintUNIString(player, 39);
  227.    Return;
  228.  
  229. # ........................................................................................
  230.  
  231. deselected:
  232.    call stop_power;
  233.    Return;
  234.  
  235. # ........................................................................................
  236.  
  237. killed:
  238.    if(GetSenderRef() != player) Return;
  239.  
  240. newplayer:
  241.    call stop_power;
  242.    Return;
  243.  
  244. # ........................................................................................
  245.  
  246. enterbubble:
  247.    inbubble = 1;
  248.    call stop_power;
  249.    Return;
  250.  
  251. # ........................................................................................
  252.  
  253. exitbubble:
  254.    inbubble = 0;
  255.    Return;
  256.  
  257. # ........................................................................................
  258.  
  259. stop_power:
  260.    SetPulse(0);
  261.    SetInvActivated(player, 39, 0);
  262.    victim = -1;
  263.    jkEndTarget();
  264.  
  265.    Return;
  266.  
  267. # ........................................................................................
  268.  
  269. get_next_target:
  270.  
  271.    victim = -1;
  272.    minDist = 99999;
  273.  
  274.    // There seem to be a bug when using values >= 180 degrees...
  275.    potential = FirstThingInView(lightning_current, 179, 5.0, 0x404);
  276.    while(potential != -1)
  277.    {
  278.       dist = VectorDist(GetThingPos(lightning_current), GetThingPos(potential));
  279.       if(
  280.          HasLOS(lightning_current, potential) &&
  281.          (potential != lightning_current) &&
  282.          (potential != player) &&
  283.          (dist <= 1.25) &&
  284.          !(GetThingFlags(potential) & 0x200) &&
  285.          !(GetActorFlags(potential) & 0x100) &&
  286.          !((jkGetFlags(potential) & 0x20) && !IsInvActivated(lightning_current, 23)) &&
  287.          (jkGetBubbleDistance(potential) > 1.0)
  288.         )
  289.       {
  290.          if(dist < minDist)
  291.          {
  292.             victim = potential;
  293.             minDist = dist;
  294.          }
  295.       }
  296.       potential = NextThingInView();
  297.    }
  298.  
  299.    Return;
  300.  
  301. # ........................................................................................
  302.  
  303. throw_lightning:
  304.  
  305.    dir = VectorNorm(VectorSub(GetThingPos(lightning_to), GetThingPos(lightning_from)));
  306.    sec = GetThingSector(lightning_from);
  307.    pos = VectorAdd(GetThingPos(lightning_from), VectorScale(dir, 0.07));
  308.  
  309.    // Did the offset take us out of the sector ?
  310.    // if so get the new sector...
  311.    if(!IsSphereInSector(pos, 0.0, sec))
  312.       sec = FindSectorAtPos(pos);
  313.  
  314.    if(sec >= 0)
  315.       CreateThingAtPos(lightning, sec, pos, dir);
  316.  
  317.    // Apply damage. The lightning bolt used doesn't do damage on itself...
  318.    if(!IsMulti())
  319.    {
  320.       if((GetThingHealth(lightning_to) > 0) && (lightning_to != GetLocalPLayerThing()))
  321.          DamageThing(lightning_to,  25, 0x08, player);
  322.    }
  323.    else
  324.    {
  325.       retval = SkillTarget(lightning_to, player, 39, 25);
  326.    }
  327.  
  328.    Return;
  329.  
  330. end
  331.  
  332.  
  333.